/*
 * @Date: 2020-08-25 16:08:38
 * @LastEditors: xujianxing
 * @LastEditTime: 2020-08-25 16:17:24
 * @FilePath: \nili\src\common\pipe\parse-int.pipe.ts
 */
/**
 * 转换管道
 */

import {
  PipeTransform,
  Injectable,
  ArgumentMetadata,
  BadRequestException,
} from '@nestjs/common';

@Injectable()
export class ParseIntPipe implements PipeTransform<string, number> {
  transform(value: string, metadata: ArgumentMetadata): number {
    const val = parseInt(value, 10);
    if (isNaN(val)) {
      throw new BadRequestException('不是Int');
    }
    return val;
  }
}
